<?php

/**
 * DataCache
 * Class for caching results
 * @author griever
 *
 */
class DataCache {
	
	private $cache = array ();
	
	/**
	 * Clear the cache
	 */
	public function clear() {
		$this->cache = array ();
	}
	
	/**
	 * 
	 * Find a value in the cache, respecting its namespace
	 * @param unknown_type $namespace the namespace to which the value belongs
	 * @param unknown_type $value the value's name
	 */
	public function find($namespace, $value) {
		$key = $this->normalizeKey ( $namespace, $value );
		if (array_key_exists ( $key, $this->getCache () )) {
			return $this->cache [$key];
		}
		return null;
	}
	
	/**
	 * 
	 * Update a value in the cache, respecting its namespace
	 * @param unknown_type $namespace the namespace to which the value belongs
	 * @param unknown_type $value the value's name
	 * @param unknown_type $content the value's new content
	 */
	public function update($namespace, $value, $content) {
		$key = $this->normalizeKey ( $namespace, $value );
		$this->cache [$key] = $content;
	}
	
	/**
	 * 
	 * Normalize a value, respecting its namespace
	 * @param unknown_type $namespace
	 * @param unknown_type $value
	 */
	public function normalizeKey($namespace, $value) {
		return $namespace . "::" . $value;
	}
	
	private function getCache() {
		return $this->cache;
	}

}

?>